import React from 'react';
import { NavBar, Icon, Modal, List, Button, WhiteSpace, WingBlank } from 'antd-mobile';
import router from 'umi/router';
import 'antd-mobile/dist/antd-mobile.css';
import styles from './index.less';
import { remoteLinkAddress } from '../../utils/ip'
import { showDingTalkHead, dingTalkTitle, backToOut } from '../../utils/utils'
const isDingTalk = localStorage.getItem("isDingTalk");
import * as dd from 'dingtalk-jsapi';
const pathShouldHideDingHead = ['/EnterpriseCertificationInformation',
	'/EnterpriseCertificationList',
	'/EnterpriseCertificationListBackUps',
	'/EnterpriseCertificationResult',
	'/ImpressionLibrary',
	'/PersonalCertification',
	'/PersonalCertificationAlipayDetail',
	'/PersonalCertificationDetail',
	'/RealNameAuthenticationResult',
	'/uploadImg',
	'/Signature',
	'/SignCertification',
	'/Authentication',
	'/editImg',
	'/SignTheSuccess',
	'/SignTheSuccess/SignatureViewer',
	'/SignCertificationResults',
	'/SignatureDetail',
]

const { alert } = Modal;

class MyNavBar extends React.Component {
	constructor(props) {
		super(props);

	}
	componentDidMount() {
		const { title } = this.props;
		const isDingTalk = localStorage.getItem('isDingTalk');
		// const {location: {pathname} } = this.props;
		if (isDingTalk === 'true') {
			const than = this;
			dingTalkTitle(title)
			// if(pathShouldHideDingHead.includes(pathname)){
			if (dd.env.platform !== "notInDingTalk") {
				dd.biz.navigation.setLeft({
					control: true,//是否控制点击事件，true 控制，false 不控制， 默认false
					android: true, // 安卓端如果需要控制左上角返回事件加上这个字段，并设置为true
					text: '',//控制显示文本，空字符串表示显示默认文本
					onSuccess: function (result) {
						than.goback();
					},
					onFail: function (err) { }
				});
				// }
			}
		}
	}



	goback = () => {
		const { backUrl = '', isExternal = '', onSave = '' } = this.props;
		if (backUrl === '' && isExternal === '' && onSave === '') {
			return
		}

		if (onSave) {
			alert('提示', '即将离开当前页，离开前保存您的最新操作', [
				{
					text: '确定', onPress: () => {
						onSave('save', backUrl, isExternal, '')
					},
				},
			]);
		}
		else {
			if (backUrl || backUrl !== '') {
				router.push(backUrl)
			}
			else if (isExternal && backUrl === '') {
				backToOut();
			} else {
				router.goBack()
			}
		}

	}

	render() {
		const { title, gobackStatus } = this.props;
		const isDingTalk = localStorage.getItem('isDingTalk');
		return (
			<div>
				{
					isDingTalk === 'true' ? 
					'' 
					: 
					<NavBar
						mode="light"
						icon={gobackStatus ? "" : <Icon type="left" className={styles.backIcon} size='lg'></Icon>}
						leftContent={gobackStatus ? "" : "返回"}
						onLeftClick={this.goback}
						className={styles.navBar}
					>{title}</NavBar>
				}
			</div>

		)
	}
}



export default MyNavBar;
